package nirvana.core.domains.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author Joseph.Li
 * @author joseph.li@king-v.com
 * update: you can use CustomPage
 * Created in 2022-07-05 16:41
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResult<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;


    /**
     * 查询数据列表
     */
    protected List<T> records = Collections.emptyList ();

    /**
     * 总数
     */
    protected long total = 0;


    /**
     * cancel this constructor
     *
     * @param list
     * @param page
     */
    private PageResult(List<T> list, IPage<T> page) {
        this.records = list;
        this.total = page.getTotal ();
    }


    /**
     *
     * @param page
     */
    public PageResult(IPage<T> page) {
        this.records = page.getRecords ();
        this.total = page.getTotal ();
    }

    public PageResult(List<T> list, Page page) {
        this.records = list;
        this.total = page.getTotal();
    }

}
